#!/usr/bin/env python
# encoding: utf-8
"""
@author: youfeng
@email: youfeng243@163.com
@license: Apache Licence
@file: schedule_conf.py
@time: 2018/1/21 20:54
"""
from config.app_conf import SEARCH_LIST_FAIL, CRAWL_DETAIL_FAIL, SEARCH_LIST_NOT_FOUND, CRAWL_DETAIL_PART_SUCCESS
from model.crawl_model import STORE_TYPE_LIST, STORE_TYPE_DETAIL, STORE_TYPE_ANNUAL

# 调度列表
SCHEDULE_LIST = [
    {
        # 当前需要调度的省份
        'province': 'gsxt',
        # 抓取表名
        'table_name': 'new_gsxt_company_list',
        # 抓取范围
        'field': STORE_TYPE_LIST,
        # 选择条件
        'select': {'$or': [{'search_status': None},
                           {'search_status': SEARCH_LIST_FAIL}]},
        # 索引，可选，如果表没有建立索引 则需要填写
        'index': ['search_status'],
        # 需要发送的队列
        'tube': 'gsxt_list_download',
    },

    # 浙江年报抓取
    {
        # 当前需要调度的省份
        'province': 'zhejiang',
        # 抓取表名
        'table_name': 'new_zhejiang_annual_list',
        # 抓取范围
        'field': STORE_TYPE_ANNUAL,
        # 选择条件
        'select': [{'$or': [{'crawl_status': None},
                            {'crawl_status': CRAWL_DETAIL_FAIL}]},
                   {'crawl_status': 2}],
        # 索引，可选，如果表没有建立索引 则需要填写
        'index': ['crawl_status'],
        # 需要发送的队列
        'tube': 'gsxt_annual_download',
    },

    {
        # 当前需要调度的省份
        'province': 'zhejiang',
        # 抓取表名
        'table_name': 'new_zhejiang_company_list',
        # 抓取范围
        'field': STORE_TYPE_DETAIL,
        # 选择条件
        'select': [{'$and': [{'$or': [{'crawl_status': None}, {'crawl_status': CRAWL_DETAIL_FAIL}]},
                             {'search_status': {'$ne': SEARCH_LIST_NOT_FOUND}}]},
                   {'$and': [{'crawl_status': CRAWL_DETAIL_PART_SUCCESS},
                             {'search_status': {'$ne': SEARCH_LIST_NOT_FOUND}}]}],
        # 索引，可选，如果表没有建立索引 则需要填写
        'index': ['search_status', 'crawl_status'],
        # 需要发送的队列
        'tube': 'zhejiang_list_download',
    },

    {
        # 当前需要调度的省份
        'province': 'jiangsu',
        # 抓取表名
        'table_name': 'new_jiangsu_company_list',
        # 抓取范围
        'field': STORE_TYPE_DETAIL,
        # 选择条件
        'select': [{'$and': [{'$or': [{'crawl_status': None}, {'crawl_status': CRAWL_DETAIL_FAIL}]},
                             {'search_status': {'$ne': SEARCH_LIST_NOT_FOUND}}]},
                   {'$and': [{'crawl_status': CRAWL_DETAIL_PART_SUCCESS},
                             {'search_status': {'$ne': SEARCH_LIST_NOT_FOUND}}]}],
        # 索引，可选，如果表没有建立索引 则需要填写
        'index': ['search_status', 'crawl_status'],
        # 需要发送的队列
        'tube': 'test_list_download',
    },

    {
        # 当前需要调度的省份
        'province': 'zhejiang',
        # 抓取表名
        'table_name': 'new_zhejiang_company_list_full_20180119',
        # 抓取范围
        'field': STORE_TYPE_LIST,
        # 选择条件
        'select': {'$or': [{'search_status': None},
                           {'search_status': SEARCH_LIST_FAIL}]},
        # 索引，可选，如果表没有建立索引 则需要填写
        'index': ['search_status'],
        # 需要发送的队列
        'tube': 'gsxt_list_download',
    },
    # {
    #     # 当前需要调度的省份
    #     'province': 'gsxt',
    #     # 抓取表名
    #     'table_name': 'beijing_shanghai_hubo_20180122',
    #     # 抓取范围
    #     'field': STORE_TYPE_DETAIL,
    #     # 选择条件
    #     'select': [{'$and': [{'$or': [{'crawl_status': None}, {'crawl_status': CRAWL_DETAIL_FAIL}]},
    #                          {'search_status': {'$ne': SEARCH_LIST_NOT_FOUND}}]},
    #                {'$and': [{'crawl_status': CRAWL_DETAIL_PART_SUCCESS},
    #                          {'search_status': {'$ne': SEARCH_LIST_NOT_FOUND}}]}],
    #     # 索引，可选，如果表没有建立索引 则需要填写
    #     'index': ['search_status', 'crawl_status'],
    #     # 需要发送的队列
    #     'tube': 'test_list_download',
    # },
]
